/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package bmacotada.orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import bmacotada.orm.*;

public class Cuestionario_1DAOImpl implements bmacotada.orm.dao.Cuestionario_1DAO {
	public Cuestionario_1 loadCuestionario_1ByORMID(int cu_id_cuestionario) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return loadCuestionario_1ByORMID(session, cu_id_cuestionario);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1 getCuestionario_1ByORMID(int cu_id_cuestionario) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return getCuestionario_1ByORMID(session, cu_id_cuestionario);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1 loadCuestionario_1ByORMID(int cu_id_cuestionario, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return loadCuestionario_1ByORMID(session, cu_id_cuestionario, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1 getCuestionario_1ByORMID(int cu_id_cuestionario, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return getCuestionario_1ByORMID(session, cu_id_cuestionario, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1 loadCuestionario_1ByORMID(PersistentSession session, int cu_id_cuestionario) throws PersistentException {
		try {
			return (Cuestionario_1) session.load(bmacotada.orm.Cuestionario_1.class, new Integer(cu_id_cuestionario));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1 getCuestionario_1ByORMID(PersistentSession session, int cu_id_cuestionario) throws PersistentException {
		try {
			return (Cuestionario_1) session.get(bmacotada.orm.Cuestionario_1.class, new Integer(cu_id_cuestionario));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1 loadCuestionario_1ByORMID(PersistentSession session, int cu_id_cuestionario, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Cuestionario_1) session.load(bmacotada.orm.Cuestionario_1.class, new Integer(cu_id_cuestionario), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1 getCuestionario_1ByORMID(PersistentSession session, int cu_id_cuestionario, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Cuestionario_1) session.get(bmacotada.orm.Cuestionario_1.class, new Integer(cu_id_cuestionario), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1[] listCuestionario_1ByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return listCuestionario_1ByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1[] listCuestionario_1ByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return listCuestionario_1ByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1[] listCuestionario_1ByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From bmacotada.orm.Cuestionario_1 as Cuestionario_1");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Cuestionario_1[]) list.toArray(new Cuestionario_1[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1[] listCuestionario_1ByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From bmacotada.orm.Cuestionario_1 as Cuestionario_1");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Cuestionario_1[]) list.toArray(new Cuestionario_1[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1 loadCuestionario_1ByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return loadCuestionario_1ByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1 loadCuestionario_1ByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return loadCuestionario_1ByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1 loadCuestionario_1ByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Cuestionario_1[] cuestionario_1s = listCuestionario_1ByQuery(session, condition, orderBy);
		if (cuestionario_1s != null && cuestionario_1s.length > 0)
			return cuestionario_1s[0];
		else
			return null;
	}
	
	public Cuestionario_1 loadCuestionario_1ByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Cuestionario_1[] cuestionario_1s = listCuestionario_1ByQuery(session, condition, orderBy, lockMode);
		if (cuestionario_1s != null && cuestionario_1s.length > 0)
			return cuestionario_1s[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateCuestionario_1ByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return iterateCuestionario_1ByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCuestionario_1ByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return iterateCuestionario_1ByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCuestionario_1ByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From bmacotada.orm.Cuestionario_1 as Cuestionario_1");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCuestionario_1ByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From bmacotada.orm.Cuestionario_1 as Cuestionario_1");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1 createCuestionario_1() {
		return new bmacotada.orm.Cuestionario_1();
	}
	
	public boolean save(bmacotada.orm.Cuestionario_1 cuestionario_1) throws PersistentException {
		try {
			bmacotada.orm.Taller1BMPersistentManager.instance().saveObject(cuestionario_1);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(bmacotada.orm.Cuestionario_1 cuestionario_1) throws PersistentException {
		try {
			bmacotada.orm.Taller1BMPersistentManager.instance().deleteObject(cuestionario_1);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(bmacotada.orm.Cuestionario_1 cuestionario_1)throws PersistentException {
		try {
			if(cuestionario_1.getPaciente_1Rut() != null) {
				cuestionario_1.getPaciente_1Rut().cuestionario_1.remove(cuestionario_1);
			}
			
			bmacotada.orm.Pregunta_1[] lPregunta_1Pr_id_preguntas = cuestionario_1.pregunta_1Pr_id_pregunta.toArray();
			for(int i = 0; i < lPregunta_1Pr_id_preguntas.length; i++) {
				lPregunta_1Pr_id_preguntas[i].cuestionario_1Cu_id_cuestionario.remove(cuestionario_1);
			}
			return delete(cuestionario_1);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(bmacotada.orm.Cuestionario_1 cuestionario_1, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(cuestionario_1.getPaciente_1Rut() != null) {
				cuestionario_1.getPaciente_1Rut().cuestionario_1.remove(cuestionario_1);
			}
			
			bmacotada.orm.Pregunta_1[] lPregunta_1Pr_id_preguntas = cuestionario_1.pregunta_1Pr_id_pregunta.toArray();
			for(int i = 0; i < lPregunta_1Pr_id_preguntas.length; i++) {
				lPregunta_1Pr_id_preguntas[i].cuestionario_1Cu_id_cuestionario.remove(cuestionario_1);
			}
			try {
				session.delete(cuestionario_1);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(bmacotada.orm.Cuestionario_1 cuestionario_1) throws PersistentException {
		try {
			bmacotada.orm.Taller1BMPersistentManager.instance().getSession().refresh(cuestionario_1);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(bmacotada.orm.Cuestionario_1 cuestionario_1) throws PersistentException {
		try {
			bmacotada.orm.Taller1BMPersistentManager.instance().getSession().evict(cuestionario_1);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Cuestionario_1 loadCuestionario_1ByCriteria(Cuestionario_1Criteria cuestionario_1Criteria) {
		Cuestionario_1[] cuestionario_1s = listCuestionario_1ByCriteria(cuestionario_1Criteria);
		if(cuestionario_1s == null || cuestionario_1s.length == 0) {
			return null;
		}
		return cuestionario_1s[0];
	}
	
	public Cuestionario_1[] listCuestionario_1ByCriteria(Cuestionario_1Criteria cuestionario_1Criteria) {
		return cuestionario_1Criteria.listCuestionario_1();
	}
}
